package com.sfc.sdsr.server.commands;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;

import org.apache.log4j.Logger;

import com.sfc.sdsr.server.dao.Dao;

public abstract class Command {

	protected final Logger log = Logger.getLogger(getClass());
	protected Dao dao;
	protected boolean shouldExecute = true;
	protected Object returnObject;
	
	public void proxyExecute() {
		if (shouldExecute) {
		    execute();
		}
	}
	
	public byte[] serializeReturn() throws IOException {
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		ObjectOutputStream oos = new ObjectOutputStream(baos);
		oos.writeObject(returnObject);
		oos.close();
		
		return baos.toByteArray();
	}

	/**
	 * Sets returnObject to the specified variable depending on what command it is
	 */
	protected abstract void execute();

}
